package top.xana.acg.common.factory

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import java.util.concurrent.Executor
import java.util.concurrent.Executors

class Factory private constructor() {
    private val executor: Executor
    private val gson: Gson

    companion object {
        private var instance: Factory? = null
        fun runOnAsync(runnable: Runnable?) {
            // 异步执行
            instance!!.executor.execute(runnable)
        }

        fun getGson(): Gson {
            return instance!!.gson
        }

        fun setup() {}

        init {
            instance = Factory()
        }
    }

    /**
     * 收到账户退出的消息需要进行账户退出重新登录
     */
    private fun logout() {}

    init {
        // 新建一个线程池
        executor = Executors.newFixedThreadPool(4)
        gson = GsonBuilder()
            .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS") // 设置一个过滤器, 数据库级别的ModeL不进行Json转换
            //.setExclusionStrategies(new DBFlowExclusionStrategy())
            .setLenient()
            .create()
    }
}